package com.zoke.daycarpool.ui;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;

import com.zoke.daycarpool.R;
import com.zoke.daycarpool.base.BaseUi;
import com.zoke.daycarpool.domain.UserBeen;
import com.zoke.daycarpool.domain.UserInstense;
import com.zoke.support.view.ZokeToast;

/**
 * 编辑名字
 * 
 * @author jack
 * 
 */
public class EditName extends BaseUi {

	private UserBeen mUser;
	private EditText mNameEt;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_editname);
		mTitleManager.setTitle("名字").setLeftIcon(R.drawable.title_back);
		mTitleManager.getTitleRight().setTextColor(
				getResources().getColor(R.color._main));
		mEnableSwipeRight = true;
		mTitleManager.setRightText("完成");
		mUser = UserInstense.getInstense(getApplicationContext()).getUser();
		mNameEt = (EditText) findViewById(R.id._edit);
		// 显示键盘
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);// 显示键盘
		if (mUser == null)
			return;
		mNameEt.setText(mUser.getUserName());
	}

	@Override
	public void onTitleClickRight(View view) {
		super.onTitleClickRight(view);
		String name = mNameEt.getText().toString().trim();
		if (TextUtils.isEmpty(name)) {
			mNameEt.setError("名字不能为空");
			return;
		}
		// ??控制长度？

		if (name.length() > 10) {
			mNameEt.setError("名字不能大于10个");
			return;
		}
		Intent intent = new Intent();
		intent.putExtra("name", "" + name);
		setResult(PersonEdit.RESULTCODE_NAME, intent);
		this.onBackPressed();
	}
}
